<template>
  <div>
    <el-button class="button" type="primary" icon="el-icon-s-management" style="margin-right: 100px;float: right" @click="ddoptimize()">优化</el-button>
    <div class="title">
      <span style="float: left;color: #ffffff">日前调度优化设置</span>
    </div>
    <div style="float: left;margin-left: 20px;">
      <span style="color: #ffffff">日前优化时长:</span>
      <el-select  v-model="before_day"  style="margin-left: 10px">
        <el-option  v-for="item in beforeTime" :key="item.value" :label="item.label" :value="item.value"></el-option>
      </el-select>
    </div>
    <div class="title" style="margin-top: 45px">
      <span style="float: left;color: #ffffff">日前调度优化目标</span>
    </div>

    <div style="float: left;margin-left: 20px;">
      <span style="color: #ffffff">优化目标:</span><el-select  v-model="target_name"  style="margin-left: 44px" @change="findyhmb(target_name)">
      <el-option  v-for="item in target"
                  :key="item.value"
                  :label="item.label"
                  :value="item.label">
      </el-option>
    </el-select>
    <el-checkbox label="经济性" :disabled="yhmbxx" style="margin-left: 90px"><span style="color: #ffffff">经济性 </span></el-checkbox><input :disabled="yhmbxx" style="width: 30px;margin-left: -25px;height: 20px;" v-model="jjqz"></input>
    <el-checkbox label="环境性" :disabled="yhmbxx" style="margin-left: 25px"><span style="color: #ffffff">环境性</span></el-checkbox><input :disabled="yhmbxx" style="width: 30px;margin-left: -25px;height: 20px;" v-model="hjqz"></input>
    <el-checkbox label="能源利用率" :disabled="yhmbxx" style="margin-left: 25px"><span style="color: #ffffff">能源利用率</span></el-checkbox><input :disabled="yhmbxx" style="width: 30px;margin-left: 5px;height: 20px;" v-model="nyqz"></input>
    </div>
    <div class="title" style="margin-top: 40px">
      <span style="float: left;color: #ffffff">日中调度优化设置</span>
    </div>
    <div style="float: left;margin-left: 20px;">
      <span style="color: #ffffff">日中优化间隔:</span><el-select  v-model="in_day"  style="margin-left: 10px">
                    <el-option  v-for="item in afterTime"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                    </el-option>
                </el-select>
      <span style="margin-left: 90px"><span style="color: #ffffff">实时数据导入:</span>
        <el-radio v-model="in_day_data_type" label="1"><span style="color: #ffffff">数据库 </span><!--<el-button type="small">设置</el-button>--></el-radio>
        <el-radio v-model="in_day_data_type" label="2"><span style="color: #ffffff">Excel文件</span>
          <el-upload  action="/iepsapi/upload"
                    :show-file-list="false"
                    :on-success="handleSuccess"
                    :before-upload="beforeUpload" style="float: right">
          <el-button type="small" style="margin-left: 20px;margin-top: -10px">打开</el-button>
        </el-upload>
        </el-radio>
      </span>
    </div>
    <div class="box2">
      <div class = "title">
        <div style="position: absolute;left: 0%;line-height: 5vh;"><span style="margin-left: 1vh;">环境参数</span></div>
      </div>

      <el-tabs v-model="activeName" style="margin-top: 0px">
            <el-row>
              <el-col :span="11" style="color: #ffffff;text-align: center">减排系数<hr style="margin-top: 5px"/>
                <table>
                  <tr>
                    <td>
                      <table style="margin-top: 15px;border-collapse: collapse">
                        <tr>
                          <td colspan="2" class="td">发电</td>
                        </tr>
                        <tr>
                          <td class="td">碳粉尘(kg/kWh)</td>
                          <td class="td"><input type="text" style="height: 100%;width: 96%;text-align:center;" v-model="paramter_setting.electricity_carbon_dust"></td>
                        </tr>
                        <tr>
                          <td class="td">二氧化碳(kg/kWh)</td>
                          <td class="td"><input type="text" style="height: 100%;width: 96%;text-align:center" v-model="paramter_setting.electricity_c02"></td>
                        </tr>
                        <tr>
                          <td class="td">二氧化硫(kg/kWh)</td>
                          <td class="td"><input type="text" style="height: 18px;width: 96%;text-align:center" v-model="paramter_setting.electricity_so2"></td>
                        </tr>
                        <tr>
                          <td class="td">氮氧化物(kg/kWh)</td>
                          <td class="td"><input type="text" style="height: 100%;width: 96%;text-align:center" v-model="paramter_setting.electricity_no"></td>
                        </tr>
                        <tr>
                          <td class="td">PM2.5(kg/kWh)</td>
                          <td class="td"><input type="text" style="height: 100%;width: 96%;text-align:center" v-model="paramter_setting.electricity_pm"></td>
                        </tr>
                        <tr>
                          <td class="td">等效植树(棵/kWh)</td>
                          <td class="td"><input type="text" style="height: 100%;width: 96%;text-align:center" v-model="paramter_setting.electricity_tree_planting"></td>
                        </tr>
                      </table>
                    </td>
                    <td>
                      <table style="margin-top: 15px;margin-left: 8px;border-collapse: collapse">
                        <tr>
                          <td colspan="2" class="td">供热</td>
                        </tr>
                        <tr>
                          <td class="td">碳粉尘(kg/kWh)</td>
                          <td class="td"><input type="text" style="height: 100%;width: 96%;text-align:center" v-model="paramter_setting.heat_carbon_dust"></td>
                        </tr>
                        <tr>
                          <td class="td">二氧化碳(kg/kWh)</td>
                          <td class="td"><input type="text" style="height: 100%;width: 96%;text-align:center" v-model="paramter_setting.heat_c02"></td>
                        </tr>
                        <tr>
                          <td class="td">二氧化硫(kg/kWh)</td>
                          <td class="td"><input type="text" style="height: 100%;width: 96%;text-align:center" v-model="paramter_setting.heat_so2"></td>
                        </tr>
                        <tr>
                          <td class="td">氮氧化物(kg/kWh)</td>
                          <td class="td"><input type="text" style="height: 100%;width: 96%;text-align:center" v-model="paramter_setting.heat_no"></td>
                        </tr>
                        <tr>
                          <td class="td">PM2.5(kg/kWh)</td>
                          <td class="td"><input type="text" style="height: 100%;width: 96%;text-align:center" v-model="paramter_setting.heat_pm"></td>
                        </tr>
                        <tr>
                          <td class="td">等效植树(棵/kWh)</td>
                          <td class="td"><input type="text" style="height: 100%;width: 96%;text-align:center" v-model="paramter_setting.heat_tree_planting"></td>
                        </tr>
                      </table>
                    </td>
                  </tr>
                </table>
              </el-col>
              <el-col :span="11" style="margin-left: 20px;color: #ffffff;text-align: center" >节能指标<hr style="margin-top: 5px"/>
                <table style="margin-top: 15px;margin-left: 15px;width: 90%;border-collapse: collapse">
                  <tr>
                    <td colspan="2" class="td">发电</td>
                  </tr>
                  <tr>
                    <td class="td">煤耗量(kg/kWh)</td>
                    <td class="td"><input type="text" style="height: 100%;width: 98.5%;text-align:center" v-model="paramter_setting.electricity_coal_consumption"></td>
                  </tr>
                  <tr>
                    <td class="td">水耗量(kg/kWh)</td>
                    <td class="td"><input type="text" style="height: 100%;width: 98.5%;text-align:center" v-model="paramter_setting.electricity_water_consumption"></td>
                  </tr>
                </table>
                <table style="margin-top: 30px;margin-left: 15px;width: 90%;border-collapse: collapse">
                  <tr>
                    <td colspan="2" class="td">供热</td>
                  </tr>
                  <tr>
                    <td class="td">煤耗量(kg/kWh)</td>
                    <td class="td"><input type="text" style="height: 100%;width: 98.5%;text-align:center" v-model="paramter_setting.heat_coal_consumption"></td>
                  </tr>
                  <tr>
                    <td class="td">水耗量(kg/kWh)</td>
                    <td class="td"><input type="text" style="height: 100%;width: 98.5%;text-align:center" v-model="paramter_setting.heat_water_consumption"></td>
                  </tr>
                </table>
              </el-col>
            </el-row>
      </el-tabs>
    </div>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        jjqz:'0.0',
        hjqz:'0.0',
        nyqz:'0.0',
        yhmbxx:true,
        in_day_data_type: '2',
        ddyhmb: '',
        in_day_data_path: "",
        paramter_setting:{
          electricity_carbon_dust: 0,
          electricity_c02: 0,
          electricity_so2: 0,
          electricity_no: 0,
          electricity_pm: 0,
          electricity_tree_planting: 0,
          electricity_coal_consumption: 0,
          electricity_water_consumption: 0,
          heat_carbon_dust: 0,
          heat_c02: 0,
          heat_so2: 0,
          heat_no: 0,
          heat_pm: 0,
          heat_tree_planting: 0,
          heat_coal_consumption:0,
          heat_water_consumption:0
        },
        beforeTime: [{
          value: '1',
          label: '一天'
        },{
          value: '2',
          label: '一周'
        }],
        before_day: '一天',
        afterTime: [
          {value: '1',
          label: '30分钟'
          },{
            value: '2',
            label: '1小时'
          },{
            value: '3',
            label: '2小时'
          },{
            value: '4',
            label: '不进行日中优化'
          }],
        in_day:"30分钟",
        target: [
          {target_id: '1',
            label: '经济性'
          },{
            target_id: '2',
            label: '环境性'
          },{
            target_id: '3',
            label: '能源利用率'
          },{
            target_id: '4',
            label: '综合最优'
          }],
        target_name:"",
        project_id: this.$root.project_id,
      }
    },
    methods: {
      //校验是不是xls或xlsx
      beforeUpload(file){
        const isXLS = file.type === 'application/vnd.ms-excel';
        if(isXLS){
          return true;
        }
        const isXLSX = file.type === 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
        if (isXLSX) {
          return true;
        }
        this.$message.error('上传文件只能是xls或者xlsx格式!');
        return false;
      },
      //上传成功提示
      handleSuccess(response, file) {
        if(response.flag){
          this.$message({
            message: response.message,
            type: 'success'
          });
          this.in_day_data_path=response.data;
        }else{
          this.$message.error(response.message);
        }
        console.log(response, file, fileList);
      },
      ddoptimize(){
        if (this.target_name=="综合最优"){
          if (this.jjqz*1+this.hjqz*1+this.nyqz*1 !=1){
            return this.$message.error("请输入正确的权重比例！");
          }
          this.$http.post("/iepsapi/dispatch/ddyh?project_id="+this.project_id,
            {"before_day": this.before_day,
              "target":"综合最优",
              "target_form": [{
                "target_name": "经济性最优",
                "target_id": 1,
                "weight": this.jjqz
              }, {
                "target_name": "环境性最优",
                "target_id": 2,
                "weight": this.hjqz
              }, {
                "target_name": "能源利用率",
                "target_id": 3,
                "weight": this.nyqz
              }],
              "in_day": this.in_day,
              "in_day_data_type": this.in_day_data_type,
              "in_day_data_path": this.in_day_data_path,
              "electricity_carbon_dust": this.paramter_setting.electricity_carbon_dust,
              "electricity_c02": this.paramter_setting.electricity_c02,
              "electricity_so2": this.paramter_setting.electricity_so2,
              "electricity_no": this.paramter_setting.electricity_no,
              "electricity_pm2.5": this.paramter_setting.electricity_pm,
              "electricity_tree_planting": this.paramter_setting.electricity_tree_planting,
              "electricity_coal_consumption": this.paramter_setting.electricity_coal_consumption,
              "electricity_water_consumption": this.paramter_setting.electricity_water_consumption,
              "heat_carbon_dust": this.paramter_setting.heat_carbon_dust,
              "heat_c02": this.paramter_setting.heat_c02,
              "heat_so2": this.paramter_setting.heat_so2,
              "heat_no": this.paramter_setting.heat_no,
              "heat_pm2.5": this.paramter_setting.heat_pm,
              "heat_tree_planting": this.paramter_setting.heat_tree_planting,
              "heat_coal_consumption": this.paramter_setting.heat_coal_consumption,
              "heat_water_consumption": this.paramter_setting.heat_water_consumption,
            }).then((res)=>{
            if (res.data.flag) {
              this.$message({
                type: 'success',
                message: res.data.message
              });
            } else {
              this.$message.error(res.data.message);
            }
          });
        }else{
          this.$http.post("/iepsapi/dispatch/ddyh?project_id="+this.project_id,
            {"before_day": this.before_day,
            "target":this.target_name,
            "target_form": [],
            "in_day": this.in_day,
            "in_day_data_type": this.in_day_data_type,
            "in_day_data_path": this.in_day_data_path,
            "electricity_carbon_dust": this.paramter_setting.electricity_carbon_dust,
            "electricity_c02": this.paramter_setting.electricity_c02,
            "electricity_so2": this.paramter_setting.electricity_so2,
            "electricity_no": this.paramter_setting.electricity_no,
            "electricity_pm2.5": this.paramter_setting.electricity_pm,
            "electricity_tree_planting": this.paramter_setting.electricity_tree_planting,
            "electricity_coal_consumption": this.paramter_setting.electricity_coal_consumption,
            "electricity_water_consumption": this.paramter_setting.electricity_water_consumption,
            "heat_carbon_dust": this.paramter_setting.heat_carbon_dust,
            "heat_c02": this.paramter_setting.heat_c02,
            "heat_so2": this.paramter_setting.heat_so2,
            "heat_no": this.paramter_setting.heat_no,
            "heat_pm2.5": this.paramter_setting.heat_pm,
            "heat_tree_planting": this.paramter_setting.heat_tree_planting,
            "heat_coal_consumption": this.paramter_setting.heat_coal_consumption,
            "heat_water_consumption": this.paramter_setting.heat_water_consumption,
            }).then((res)=>{
            if (res.data.flag) {
              this.$message({
                type: 'success',
                message: res.data.message
              });
            } else {
              this.$message.error(res.data.message);
            }
          });
        }
      },
      findyhmb(target_name){
        if (target_name=="综合最优") {
          this.yhmbxx=false;
        }else{
          this.yhmbxx=true;
        }
      }
    }
  }
</script>
<style scoped>
  .title{
    width:100%;
    height:6vh;
    background: rgb(55, 69, 144);
    font-size:2vh;
    font-weight:bold;
    background: inherit;
    -webkit-box-shadow: none;
    border-radius: 1px;
    -moz-box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.345098039215686);
    -webkit-box-shadow: 0px 1px 1px rgba(0, 0, 0, 0.345098039215686);
    box-shadow: 0px 0px 1px rgba(0, 0, 0, 0.345098039215686);
  }
  .td{
    border: 1px blue solid;
    width: 220px;
    height: 10px;
    text-align: center;
  }
  input{
    background-color: #2d3d88;
    color: #ffffff
  }
  .box2{
    position: relative;
    width: 100%;
    height: 50%;
    margin-top:3%;
    background: inherit;
    background-color: rgba(45, 61, 136, 0.6);
    color: white;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    border-width: 1px;
    border-style: solid;
    border-color: rgba(226, 239, 249, 1);
    border : none;
    border-radius: 5px;
    -webkit-box-shadow: 0px 2px 1px rgba(0, 0, 0, 0.345098039215686);
    box-shadow: 0px 2px 1px rgba(0, 0, 0, 0.345098039215686);
    font-size: 2vh;
    text-align: right;
    top: 20px;
  }
</style>
